#include "commitwidget.h"
#include "ui_commitwidget.h"

// Qt
#include <QLabel>
#include <QProgressBar>

// QApt
#include <QApt/Transaction>


CommitWidget::CommitWidget(QWidget *parent) : QWidget(parent), ui(new Ui::CommitWidget)
{
    ui->setupUi(this);
    m_commitLabel = ui->commitLabel;
    m_progressBar = ui->progressBar;
}

CommitWidget::~CommitWidget()
{
    delete ui;
}

void CommitWidget::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void CommitWidget::setTransaction(QApt::Transaction *trans)
{
    m_trans = trans;
    connect(m_trans, SIGNAL(statusDetailsChanged(QString)), m_commitLabel, SLOT(setText(QString)));
    connect(m_trans, SIGNAL(progressChanged(int)), m_progressBar, SLOT(setValue(int)));
    m_progressBar->setValue(trans->progress());
}

void CommitWidget::clear()
{
    m_commitLabel->setText(QString());
    m_progressBar->setValue(0);
    m_trans = 0;
}
